<link rel="stylesheet" href="{assets('css', 'themes/card.css')}">
<section class="section">
	<noscript>JavaScript is required for this section to work!</noscript>
  <div class="columns is-multiline is-vcentered">
		{foreach $feed->items as $item}
		{do $share_url = url_video_external($item->author->uniqueId, $item->id)}
    <div class="column is-one-quarter clickable-img" id="{$item->id}" onclick="openVideo(this.id)"
			data-video_url="{url_stream($item->video->playAddr)}"
			data-video_download_watermark="{url_download($item->video->playAddr, $item->author->uniqueId, $item->id, true)}"
			data-video_download_nowatermark="{url_download(url_video_external($item->author->uniqueId, $item->id), $item->author->uniqueId, $item->id, false)}"
			data-video_share_url="{$share_url}"
			data-desc="{$item->desc}"
			data-createtime="{$item->createTime}"
      data-music_title="{$item->music->title}"
      data-music_url="{url_stream($item->music->playUrl)}">
      <img loading="lazy" src="{url_stream($item->video->originCover)}" />
			<img class="hidden" loading="lazy" data-src="{url_stream($item->video->dynamicCover)}" />
    </div>
    {/foreach}
		{if empty($feed->items)}
		<p class="title">No items sent by TikTok!</p>
		{/if}
  </div>
	{include './common/controls.latte'}
</section>

<!-- MODAL -->
<div id="modal" class="modal">
	<div id="modal-background" class="modal-background"></div>
	<div class="modal-card">
		<header class="modal-card-head">
			<button id="modal-close" class="delete" aria-label="close"></button>
			<p class="modal-card-title" id="item_title"></p>
		</header>
		<section class="modal-card-body has-text-centered" style="overflow: hidden;">
			<video id="video" autoplay controls></video>
    </section>
		<footer class="modal-card-foot has-text-centered">
			<div class="container">
				<p id="item_date"></p>
				<div class="field has-addons has-addons-centered">
					<div class="control">
						<input id="share_input" class="input" readonly />
					</div>
					<div class="control">
						<button class="button is-primary" onclick="copyShare()">Copy</button>
					</div>
				</div>
				<div id="download_dropdown" class="dropdown is-hoverable">
					<div class="dropdown-trigger">
						<button id="download_button" class="button" aria-haspopup="true" aria-controls="dropdown-menu">Download</button>
					</div>
					<div class="dropdown-menu" role="menu">
						<div class="dropdown-content">
							<a id="download_watermark" target="_blank" class="dropdown-item">With watermark</a>
							<a id="download_nowatermark" target="_blank" class="dropdown-item">Without watermark</a>
						</div>
					</div>
				</div>
        <p id="audio_title"></p>
        <audio id="audio" controls preload="none"></audio>
        <div class="buttons is-centered">
					<button id="back-button" class="button is-danger">Back</button>
          <button id="next-button" class="button is-success">Next</button>
        </div>
      </div>
    </footer>
  </div>
</div>
<script src="{assets('js', 'themes/card.js')}"></script>
